﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace DAL
{
    public class Home
    {
        public static void insert(HomeEntity home)
        {
            DbHelper.ExecuteNonQuery("p_Home_insert",
                home.Area,
                home.FileName,
                home.Text,
                home.Url,
                home.IsShow,
                home.Sort
            );
        }

        public static void update(HomeEntity home)
        {
            DbHelper.ExecuteNonQuery("p_Home_update",
                home.HomeId,
                home.Area,
                home.FileName,
                home.Text,
                home.Url,
                home.IsShow,
                home.Sort
            );
        }

        public static void delete(int homeId)
        {
            DbHelper.ExecuteNonQuery("p_Home_delete", homeId);
        }

        public static HomeEntity getById(int homeId)
        {
            DataRow dr = DbHelper.ExecuteDataRow("p_home_getById", homeId);
            HomeEntity home = new HomeEntity();
            if (dr != null)
            {
                home.HomeId = int.Parse(dr["HomeId"].ToString());
                home.Area = dr["Area"].ToString();
                home.FileName = dr["FileName"].ToString();
                home.Text = dr["Text"].ToString();
                home.Url = dr["Url"].ToString();
                home.IsShow = bool.Parse(dr["IsShow"].ToString());
                home.Sort = int.Parse(dr["Sort"].ToString());
            }
            return home;
        }
        public static DataTable list()
        {
            return DbHelper.ExecuteSqlDataTable("SELECT *FROM dbo.Home order by sort");
        }
    }
}
